<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改纪检风采')" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-arrange-edit" th:object="${demeanorArrange}">
            <input name="arrangeId" th:field="*{arrangeId}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">标题：</label>
                <div class="col-sm-8">
                    <input name="demeanorTitle" th:field="*{demeanorTitle}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">分类：</label>
                <div class="col-sm-8">
                    <select name="demeanorCategory" class="form-control m-b" th:with="type=${@dict.getType('demeanor_category')}" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{demeanorCategory}"></option>
                    </select>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">封面图片：</label>
                <div class="col-sm-8">
                    <input id="coverPhoto" name="coverPhoto" type="hidden" th:value="*{coverPhoto}" required>
                    <div class="file-loading">
                        <input id="file-upload-pic" name="file" class="form-control file-upload" type="file" data-show-preview="false" multiple>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">附件：</label>
                <div class="col-sm-8">
                    <input id="attachments" name="attachments" type="hidden" th:value="*{attachments}">
                    <div class="file-loading">
                        <input id="file-loading-video" name="file" class="form-control file-upload" type="file" data-show-preview="false" multiple>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">摘要：</label>
                <div class="col-sm-8">
                    <input name="summary" th:field="*{summary}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">关键标签：</label>
                <div class="col-sm-8">
                    <input name="keyTags" th:field="*{keyTags}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">内容：</label>
                <div class="col-sm-8">
                    <input type="hidden" class="form-control" th:field="*{demeanorContent}">
                    <div class="summernote" id="demeanorContent"></div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <input name="remark" th:field="*{remark}" class="form-control" type="text">
                </div>
            </div>
        </form>
    </div>

    <div class="row">
        <div class="col-sm-offset-5 col-sm-10">
            <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
            <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭</button>
        </div>
    </div>

    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <th:block th:include="include :: summernote-js" />
    <script th:inline="javascript">
        var prefix = ctx + "demeanor/arrange";
        $("#form-arrange-edit").validate({
            focusCleanup: true
        });


        // 附件上传初始化
        $(function(){
            let demeanorCategory = [[${demeanorArrange.demeanorCategory}]];
            initUploadFileInfo("coverPhoto", "file-upload-pic", [], "");
            if (demeanorCategory == 4) {
                initUploadFileInfo("attachments", "file-loading-video", ["mp4"], "");
            } else {
                initUploadFileInfo("attachments", "file-loading-video", [], "");

            }

        })


        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-arrange-edit').serialize());
            }
        }




        // 编辑器上传文件
        function sendFile(file, obj) {
            var data = new FormData();
            data.append("file", file);
            $.ajax({
                type: "POST",
                url: ctx + "common/upload",
                data: data,
                cache: false,
                contentType: false,
                processData: false,
                dataType: 'json',
                success: function (result) {
                    if (result.code == web_status.SUCCESS) {
                        $(obj).summernote('editor.insertImage', result.url, result.fileName);
                    } else {
                        $.modal.alertError(result.msg);
                    }
                },
                error: function (error) {
                    $.modal.alertWarning("图片上传失败。");
                }
            });
        }


        $(function() {
            $('.summernote').summernote({
                lang: 'zh-CN',
                callbacks: {
                    onChange: function(contents, $edittable) {
                        $("input[name='" + this.id + "']").val(contents);
                    },
                    onImageUpload: function(files) {
                        var obj = this;
                        var data = new FormData();
                        data.append("file", files[0]);
                        $.ajax({
                            type: "post",
                            url: ctx + "common/upload",
                            data: data,
                            cache: false,
                            contentType: false,
                            processData: false,
                            dataType: 'json',
                            success: function(result) {
                                if (result.code == web_status.SUCCESS) {
                                    $('#' + obj.id).summernote('insertImage', result.url);
                                } else {
                                    $.modal.alertError(result.msg);
                                }
                            },
                            error: function(error) {
                                $.modal.alertWarning("图片上传失败。");
                            }
                        });
                    }
                }
            });
        });


    </script>
</body>
</html>